package com.fin.zw.intelligentbot.job;

import com.fin.zw.intelligentbot.service.SocketService;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.SchedulerException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;

public class TaskJob implements Job {
    private Logger logger = LoggerFactory.getLogger(TaskJob.class);

    @Autowired
    private SocketService socketService;

    @Autowired
    TaskServiceJob taskServiceJob;

    @Override
    public void execute(JobExecutionContext context) {

        String jobName = context.getJobDetail().getKey().getName();
        int lastIndexOf = jobName.lastIndexOf("_");
        String taskId = jobName.substring(lastIndexOf + 1);
        logger.info("开始执行定时任务taskId："+taskId);
        System.out.println(context.getJobDetail().getKey().getName());
        socketService.sendTaskInfoById(taskId);
        logger.info("任务taskId："+taskId+"执行结束");
        try {
            taskServiceJob.deleteJob(jobName,"group1");
        } catch (SchedulerException e) {
            e.printStackTrace();
        }
    }
}
